package com.yunxi.controller.sys;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sys.pojo.AttachVO;
import com.yunxi.sys.service.AttachDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-07
 */
@RestController
@RequestMapping("/admin/attach")
@Api(tags = "sys:attach", description = "附件接口")
public class AttachController {
   private static final Logger logger = LoggerFactory.getLogger(AttachController.class);

   @Autowired
   AttachDubboService sysAttachDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   @ApiImplicitParams(
           {@ApiImplicitParam(paramType = "query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
                   @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页数量", required = true, dataType = "int")})
   public ApiResult page(AttachVO sysAttachVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(sysAttachDubboService.findPageByVO(sysAttachVO, pageNum, pageSize));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询分页")
   @ApiImplicitParams(
           {@ApiImplicitParam(paramType = "query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
                   @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页数量", required = true, dataType = "int")})
   public ApiResult list(AttachVO sysAttachVO) throws Exception {
      return ResponseUtil.ok(sysAttachDubboService.listByVo(sysAttachVO));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(sysAttachDubboService.getById(id));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody AttachVO sysAttachVo, @CurrentUser LoginInfo loginInfo) throws Exception {
      sysAttachDubboService.saveOrUpdate(sysAttachVo);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/saveBatch")
   @ApiOperation(value = "批量保存附件信息")
   public ApiResult save(@RequestBody List<AttachVO> attachVOList, @CurrentUser LoginInfo loginInfo) throws Exception {
         sysAttachDubboService.save(attachVOList);

      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<AttachVO> sysAttachVoList) throws Exception {
      sysAttachDubboService.removeByListVo(sysAttachVoList);
      return ResponseUtil.ok("success");
   }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(sysAttachDubboService.findMapByPageList(params));
}*/
}
